home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / Snippets / Devices / DisableEjectƒ / CtrlPatch.a next >
Encoding:
Text File  |  1992-07-15  |  1.5 KB  |  72 lines  |  [TEXT/MPS ]

  1.     INCLUDE 'traps.a'
  2.     INCLUDE 'SysEqu.a'
  3.     INCLUDE 'SysErr.a'
  4.     
  5. Control EQU $A004
  6.     
  7. PatchIt    PROC    EXPORT
  8.     
  9.     IMPORT    MyCtrl
  10.     IMPORT    OldCtrlPtr
  11.     IMPORT    MyProcEnd
  12.     
  13.     lea            MyProcEnd,a2
  14.     lea            MyCtrl,a3
  15.     suba.l        a3,a2
  16.     move.l        a2,d0                    ;make a block in the sys heap this big
  17.     _NewPtr        ,SYS
  18.     move.l        a0,d1                    ;keep new ptr around for later, and test it
  19.     beq.s        exit                    ;if nil, give up
  20.     move.l        a0,a1                    ;make a destination ptr
  21.     lea            MyCtrl,a0                ;make a source ptr
  22.     move.l        a2,d0                    ;make how many to move
  23.     _BlockMove                            ;move some bytes
  24.  
  25.     move.l        d1,a1                    ;get the address of the pointer in sys heap
  26.     move.w        #Control,d0                ;now get the address of the _Control routine
  27.     _GetTrapAddress        ,NEWOS
  28.     move.l        a0,OldCtrlPtr-MyCtrl(a1) ;save it for later
  29.     
  30.     move.w        #Control,d0                ;set up trap num
  31.     move.l        a1,a0                    ;set up new trap address
  32.     _SetTrapAddress            ,NEWOS        ;install the patch
  33. exit    
  34.     rts
  35.     
  36.     ENDP
  37.     
  38. MyCtrl    PROC    EXPORT
  39.  
  40.     IMPORT    OldCtrlPtr
  41.  
  42.     cmpi.w        #-5,ioRefNUm(a0)
  43.     bne.s        PassItOn
  44.     cmpi.w        #ejectCode,csCode(a0)
  45.     bne.s        PassItOn
  46.     move.w        IODrvNum(a0),D0                ; keep the drive number for postEvent msg
  47.     move.w        #noErr,ioResult(a0)
  48.     tst.l        ioCompletion(a0)
  49.     beq.s        exit
  50.     movem.l        a0-a1/d0-d2,-(sp)
  51.     move.l        ioCompletion(a0),a1
  52.     jsr            (a1)
  53.     movem.l        (sp)+,a0-a1/d0-d2
  54. exit
  55.     MOVE.L      #diskInsertEvt, A0                ; get event number where it belongs
  56.     _PostEvent                                ; post the event
  57.     rts
  58. PassItOn
  59.     move.l        OldCtrlPtr,-(sp)
  60.     rts
  61.     
  62.     ENDP
  63.     
  64. OldCtrlPtr    PROC    EXPORT
  65.         DC.L    0
  66.  
  67.     ENDP
  68.     
  69. MyProcEnd    PROC    EXPORT
  70.             ENDP
  71.             
  72.             END